#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 410;

int n, m;
vector<PII> dis;
int g[N][N];
PII q[N * N * 4];

void bfs(){


    int hh = 0, tt = -1;
    g[1][1] = 0;
    q[++tt] = {1, 1};
    while(hh <= tt){
        PII temp = q[hh++];
        int x = temp.first, y = temp.second, cnt = g[x][y];

        for(int i = 0; i < dis.size(); i ++){
            int nx = x + dis[i].first, ny = y + dis[i].second;
            if(nx < 1 || nx > n || ny < 1 || ny > n) continue;
            if(g[nx][ny] != -1) continue;

            g[nx][ny] = cnt + 1;
            q[++tt] = {nx, ny};
        }
    }
    

}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    for(int i = 0; i < N; i ++){
        for(int j = 0; j < N; j ++){
            g[i][j] = -1;
        }
    }

    cin >> n >> m;

    for(int i = 0; i <= 400; i ++){
        for(int j = 0; j <= 400; j ++){
            if((i * i + j * j) == m){
                if(i == 0){
                    dis.push_back({i, j});
                    dis.push_back({i, -j});
                }else if(j == 0){
                    dis.push_back({i, j});
                    dis.push_back({-i, j});
                }else{
                    dis.push_back({i, j});
                    dis.push_back({i, -j});
                    dis.push_back({-i, j});
                    dis.push_back({-i, -j});
                }
            }
        }
    }

    bfs();

    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= n; j ++){
            cout << g[i][j] << " ";
        }
        cout << '\n';
    }



    return 0;
}